package com.one.rope.mvp.web.controller.user;

import com.one.rope.mvp.basecore.annotation.LogMethod;
import com.one.rope.mvp.web.common.dto.admin.company.EditCompanyDTO;
import com.one.rope.mvp.web.common.dto.admin.team.SaveTeamMemberDTO;
import com.one.rope.mvp.web.common.dto.admin.team.TeamMemberDetailVO;
import com.one.rope.mvp.basecore.bean.ResponseObject;
import com.one.rope.mvp.web.common.dto.user.business.BusinessIndexVO;
import com.one.rope.mvp.web.common.dto.user.business.CompanyDetailVO;
import com.one.rope.mvp.web.common.dto.user.business.CompanyMemberListVO;
import com.one.rope.mvp.web.common.dto.user.business.PartnerDetailVO;
import com.one.rope.mvp.web.common.dto.user.business.PartnerListVO;
import com.one.rope.mvp.web.common.dto.user.business.ProjectDetailVO;
import com.one.rope.mvp.web.common.dto.user.business.ProjectListVO;
import com.one.rope.mvp.web.common.dto.user.business.SavePartnerDTO;
import com.one.rope.mvp.web.common.dto.user.business.SaveProjectDTO;
import com.one.rope.mvp.web.common.util.ObjectUtils;
import com.one.rope.mvp.web.controller.BaseController;
import com.one.rope.mvp.web.service.company.BusinessDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;

import io.swagger.annotations.ApiOperationSort;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 小程序企业端数据控制器
 * <p>
 *
 * @author ： Weijian.Liu
 * @date ： 2020/3/15 19:28
 */
@Api(tags = "B3小程序端-企业端数据模块")
@RequestMapping("/user")
@RestController
@Slf4j
public class BusinessDataController extends BaseController {

  @Autowired
  BusinessDataService businessDataService;

  @LogMethod
  @ApiOperation(value = "001企业端首页", notes = "企业端首页数据接口", response = BusinessIndexVO.class, position = 1)
  @ApiOperationSort(value = 1)
  @GetMapping("/api/business/index")
  public ResponseObject<BusinessIndexVO> businessIndex(){
    try {
      return businessDataService.businessIndex();
    } catch (Exception e) {
      log.error("/user/api/business/index接口异常", e);
      return ResponseObject.systemError(e);
    }
  }

  @LogMethod
  @ApiOperation(value = "002项目列表", notes = "项目列表接口", response = ProjectListVO.class)
  @ApiOperationSort(value = 2)
  @GetMapping("/api/business/projectList")
  public ResponseObject<List<ProjectListVO>> projectList(){
    try {
      return businessDataService.projectList();
    } catch (Exception e) {
      log.error("/user/api/business/projectList接口异常", e);
      return ResponseObject.systemError(e);
    }
  }

  @LogMethod
  @ApiOperation(value = "003保存项目", notes = "保存项目接口")
  @PostMapping("/api/business/saveProject")
  public ResponseObject saveProject(@RequestBody SaveProjectDTO requestDTO){
    ObjectUtils.requestNonEmpty(requestDTO.getName(), "名称不能为空");
    ObjectUtils.requestNonNull(requestDTO.getMemberScale(), "成员规模不能为空");
    ObjectUtils.requestNonNull(requestDTO.getProjectProgress(), "项目进展不能为空");
    ObjectUtils.requestNonEmpty(requestDTO.getProjectBrief(), "项目简介不能为空");
    try {
      return businessDataService.saveProject(requestDTO);
    } catch (Exception e) {
      log.error("/user/api/business/saveProject接口异常", e);
      return ResponseObject.systemError(e);
    }
  }

  @LogMethod
  @ApiOperation(value = "004项目详情", notes = "项目详情接口", response = ProjectDetailVO.class)
  @GetMapping("/api/business/projectDetail/{projectId}")
  public ResponseObject<ProjectDetailVO> projectDetail(@PathVariable("projectId") Long projectId){
    try {
      return businessDataService.projectDetail(projectId);
    } catch (Exception e) {
      log.error("/user/api/business/projectDetail接口异常", e);
      return ResponseObject.systemError(e);
    }
  }

  @LogMethod
  @ApiOperation(value = "005删除项目", notes = "删除项目接口")
  @GetMapping("/api/business/delProject/{projectId}")
  public ResponseObject delProject(@PathVariable("projectId") Long projectId){
    try {
      return businessDataService.delProject(projectId);
    } catch (Exception e) {
      log.error("/user/api/business/projectList接口异常", e);
      return ResponseObject.systemError(e);
    }
  }

  @LogMethod
  @ApiOperation(value = "006合伙人岗位列表", notes = "合伙人岗位列表接口", response = PartnerListVO.class)
  @GetMapping("/api/business/partnerList")
  public ResponseObject<List<PartnerListVO>> partnerList(){
    try {
      return businessDataService.partnerList();
    } catch (Exception e) {
      log.error("/user/api/business/partnerList接口异常", e);
      return ResponseObject.systemError(e);
    }
  }

  @LogMethod
  @ApiOperation(value = "007合伙人岗位详情", notes = "合伙人岗位详情接口", response = PartnerDetailVO.class)
  @GetMapping("/api/business/partnerDetail/{partnerId}")
  public ResponseObject<PartnerDetailVO> partnerDetail(@PathVariable("partnerId") Long partnerId){
    try {
      return businessDataService.partnerDetail(partnerId);
    } catch (Exception e) {
      log.error("/user/api/business/partnerDetail接口异常", e);
      return ResponseObject.systemError(e);
    }
  }

  @LogMethod
  @ApiOperation(value = "008删除合伙人岗位", notes = "删除合伙人岗位接口")
  @GetMapping("/api/business/delPartner/{partnerId}")
  public ResponseObject delPartner(@PathVariable("partnerId") Long partnerId){
    try {
      return businessDataService.delPartner(partnerId);
    } catch (Exception e) {
      log.error("/user/api/business/delPartner接口异常", e);
      return ResponseObject.systemError(e);
    }
  }

  @LogMethod
  @ApiOperation(value = "008保存合伙人岗位", notes = "保存合伙人岗位接口")
  @PostMapping("/api/business/savePartner")
  public ResponseObject savePartner(@RequestBody SavePartnerDTO requestDTO){
    ObjectUtils.requestNonNull(requestDTO.getPartnerType(), "合伙人类型不能为空");
    ObjectUtils.requestNonEmpty(requestDTO.getName(), "岗位名称不能为空");
    ObjectUtils.requestNonEmpty(requestDTO.getProvinceCode(), "城市省不能为空");
    ObjectUtils.requestNonEmpty(requestDTO.getCityCode(), "城市市不能为空");
    ObjectUtils.requestNonNull(requestDTO.getEducationAptitude(), "教育资质不能为空");
    ObjectUtils.requestNonNull(requestDTO.getWorkForm(), "工作形态不能为空");
    ObjectUtils.requestNonEmpty(requestDTO.getRequireDesc(), "需求描述不能为空");
    ObjectUtils.requsetCondition(requestDTO.getIncentiveList().size() > 0, "请至少选择一种激励方案");
    try {
      return businessDataService.savePartner(requestDTO);
    } catch (Exception e) {
      log.error("/user/api/business/savePartner接口异常", e);
      return ResponseObject.systemError(e);
    }
  }

  @LogMethod
  @ApiOperation(value = "009编辑企业", notes = "编辑企业接口")
  @PostMapping("/api/business/editCompany")
  public ResponseObject editCompany(@RequestBody EditCompanyDTO requestDTO){
    ObjectUtils.requestNonEmpty(requestDTO.getName(), "企业全称不能为空");
    ObjectUtils.requestNonNull(requestDTO.getFinanceStage(), "融资阶段不能为空");
    ObjectUtils.requestNonNull(requestDTO.getMemberScale(), "成员规模不能为空");
    try {
      return businessDataService.editCompany(requestDTO);
    } catch (Exception e) {
      log.error("/user/api/business/editCompany接口异常", e);
      return ResponseObject.systemError(e);
    }
  }

  @LogMethod
  @ApiOperation(value = "010企业详情", notes = "企业详情接口", response = CompanyDetailVO.class)
  @GetMapping("/api/business/companyDetail")
  public ResponseObject<CompanyDetailVO> companyDetail(){
    try {
      return businessDataService.companyDetail();
    } catch (Exception e) {
      log.error("/user/api/business/companyDetail接口异常", e);
      return ResponseObject.systemError(e);
    }
  }

  @LogMethod
  @ApiOperation(value = "011核心团队成员列表", notes = "核心团队成员列表接口")
  @GetMapping("/api/business/companyMemberList")
  public ResponseObject<List<CompanyMemberListVO>> companyMemberList(){
    try {
      return businessDataService.companyMemberList();
    } catch (Exception e) {
      log.error("/user/api/business/companyMemberList接口异常", e);
      return ResponseObject.systemError(e);
    }
  }

  @LogMethod
  @ApiOperation(value = "012保存核心团队成员", notes = "保存核心团队成员接口")
  @PostMapping("/api/business/saveCompanyMember")
  public ResponseObject saveCompanyMember(@RequestBody SaveTeamMemberDTO requestDTO){
    ObjectUtils.requestNonEmpty(requestDTO.getName(), "姓名不能为空");
    ObjectUtils.requestNonNull(requestDTO.getSex(), "称谓不能为空");
    ObjectUtils.requestNonEmpty(requestDTO.getBirthday(), "生日不能为空");
    ObjectUtils.requestNonNull(requestDTO.getPostName(), "任职岗位不能为空");
    try {
      return businessDataService.saveCompanyMember(requestDTO);
    } catch (Exception e) {
      log.error("/user/api/business/saveCompanyMember接口异常", e);
      return ResponseObject.systemError(e);
    }
  }

  @LogMethod
  @ApiOperation(value = "013删除核心团队成员", notes = "删除核心团队成员接口")
  @GetMapping("/api/business/delCompanyMember/{id}")
  public ResponseObject delCompanyMember(@PathVariable("id") Long id){
    try {
      return businessDataService.delCompanyMember(id);
    } catch (Exception e) {
      log.error("/user/api/business/delCompanyMember接口异常", e);
      return ResponseObject.systemError(e);
    }
  }

  @LogMethod
  @ApiOperation(value = "014核心团队成员详情", notes = "核心团队成员详情接口", response = TeamMemberDetailVO.class)
  @GetMapping("/api/business/companyMemberDetail/{id}")
  public ResponseObject companyMemberDetail(@PathVariable("id") Long id){
    try {
      return businessDataService.companyMemberDetail(id);
    } catch (Exception e) {
      log.error("/user/api/business/companyMemberDetail接口异常", e);
      return ResponseObject.systemError(e);
    }
  }
}
